package main

import (
	"fmt"
	"runtime"
)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	var rw chan int
	rw = make(chan int, 10)
	stop := make(chan int)
	function := func(num int) {
	L1:
		for true {
			select {
			case val := <-rw:
				if val == 2000 {
					fmt.Printf("go %d break: %d \n", num, val)
					break L1
				}
				fmt.Printf("go %d : %d\n", num, val)
				/*for val > 0 {
					val--
				}*/
			}
		}

		stop <- 2001
	}

	go function(1)
	go function(2)

	for i := 0; i < 2000; i++ {
		rw <- i
	}

	rw <- 2000
	rw <- 2000

	fmt.Printf("main go receive: %d\n", <-stop)
	fmt.Printf("main go receive: %d\n", <-stop)
}
